package com.games.portal.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class GamesDatabase extends SQLiteOpenHelper {
	private static final String DEBUG_TAG = "GamesDatabase";
	private static final int DB_VERSION = 1;
	private static final String DB_NAME = "games_data";

	public static final String TABLE_GAMES = "games";
	public static final String ID = "_id";
	public static final String COL_NAME = "title";
	public static final String COL_URL = "url";
	public static final String COL_IMAGE_URL = "image_url";
	public static final String COL_CATEGORY_NAME = "category_name_url";


	private static final String CREATE_TABLE_GAMES = "create table " + TABLE_GAMES
			+ " (" + ID + " integer primary key autoincrement, " + COL_NAME
			+ " text not null, " + COL_URL + " text not null, " 
			+ COL_IMAGE_URL + " text not null, " + COL_CATEGORY_NAME + " text not null);";
	private static final String DB_SCHEMA = CREATE_TABLE_GAMES;
	public static final String COL_CATEGORY_IMAGE = null;


	public GamesDatabase(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DB_SCHEMA);
	}
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(DEBUG_TAG, "Upgrading database. Existing contents will be lost. ["
				+ oldVersion + "]->[" + newVersion + "]");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_GAMES);
		onCreate(db);
	}
}